package com.harmonk.firstscene.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import androidx.room.Delete
import androidx.room.OnConflictStrategy
import com.harmonk.firstscene.db.entity.Person
import kotlinx.coroutines.flow.Flow

@Dao
interface PersonDao {
    @Query("SELECT * FROM persons WHERE personId = :id")
    suspend fun getPersonById(id: Long): Person?

    @Query("SELECT * FROM persons WHERE eventId = :eventId")
    fun getPersonsByEventId(eventId: Long): Flow<List<Person>>

    @Query("SELECT * FROM persons WHERE vehicleId = :vehicleId")
    fun getPersonsByVehicleId(vehicleId: Long): Flow<List<Person>>

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun insertPerson(person: Person): Long

    @Update
    suspend fun updatePerson(person: Person)

    @Delete
    suspend fun deletePerson(person: Person)
    
    @Query("DELETE FROM persons WHERE eventId = :eventId")
    suspend fun deletePersonsByEventId(eventId: Long): Int
}